package esay.array;

/**
 * 将所有0往后移动
 * @author ruizhou
 * @date 26.02.2018
 */
public class MoveZeroes {
    private static void moveZeroes(int[] nums) {
        if(nums.length < 2) return;
        int k = 0;
        for(int i = 0; i < nums.length; i++) {
            if(nums[i] != 0) {
                nums[k++] = nums[i];
            }
        }
        for(;k < nums.length; k++)
            nums[k] = 0;
    }

    public static void main(String[] args) {
        int[] nums = {0,1,3,4,0};
        moveZeroes(nums);
        System.out.println(nums);
    }
}
